﻿//
// Copyright (c) 2024 BPergaofeng
//
#include "NvCodec/nvenc.h"
#include "QsvCodec/QsvEncoder.h"
#include <bperutil/BPerAvInfoType.h>
#include <string>

class BPerH264EncoderGpu {
public:
    BPerH264EncoderGpu &operator=(const BPerH264EncoderGpu &) = delete;

    BPerH264EncoderGpu(const BPerH264EncoderGpu &) = delete;

    BPerH264EncoderGpu(BPerVideoInfo *pcontext, BPerVideoEncInfo *enc);

    virtual ~BPerH264EncoderGpu();

    void setCodec(std::string codec);

    bool init();

    void Destroy();

    int encode(BPerFrame *pframe);

    int GetSequenceParams(uint8_t *out_buffer, int out_buffer_size);

    bool isSuported();

private:
    bool isKeyFrame(const uint8_t *data, uint32_t size);

    std::string codec_;
    uint8_t *m_outBuf;
    uint8_t *m_inBuf;
    void *nvenc_data_ = nullptr;
    QsvEncoder qsv_encoder_;
    BPerVideoInfo *m_context;
    BPerVideoEncInfo *m_enc;
    BPerYuvType m_format;
    //ffmpeg::H264Encoder h264_encoder_;
};
